import React from 'react'
import { Route, Routes, Navigate } from 'react-router-dom'
import Login from './pages/Login'
import Home from './pages/Home'

export default function App() {

    let isLogin = localStorage.getItem('token')


    return (
        <div>
            {/* 注册路由 */}

            {/* {
                isLogin ? (
                    <Routes>
                        <Route path="/" element={<Login />}></Route>
                        <Route path="/home/*" element={<Home />}></Route>
                        <Route path="*" element={<Login />}></Route>
                    </Routes>
                ) : (
                    <Routes>
                        <Route path="/" element={<Login />}></Route>
                        <Route path="/login" element={<Login />}></Route>
                        <Route path="*" element={<Login />}></Route>
                    </Routes>
                )
            } */}
            <Routes>
                <Route path='/' element={<Login></Login>}></Route>
                <Route path='/login' element={<Login></Login>}></Route>

                

                {
                    isLogin ? <Route path='/home/*' element={<Home></Home>} ></Route>
                        : <Route path='/home/*' element={<Navigate to="/login" replace={true} />} ></Route>
                }

                <Route path='*' element={<Navigate to="/login" replace={true} />}></Route>
            </Routes> 
        </div>
    )
}
